package kr.or.kead.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import kr.or.kead.utils.MysqlCon;

public class PostService {
	public ArrayList<String> selectedAdderByDong(String dong) {
		Connection con = MysqlCon.getConnection();
		ArrayList<String> addrs = new ArrayList<>();
		String sql = "SELECT zipcode, sido, gugun, dong, bunji FROM post WHERE dong like ?";
		PreparedStatement pstmt = null;
		try {
			pstmt = con.prepareStatement(sql);
			pstmt.setString(1, "%"+dong+"%");
			ResultSet rs = pstmt.executeQuery();
			String str;
			while(rs.next()) {
				/*
				for(int i=1;i<6;i++) {
					sb.append(rs.getString(i) + " ");
				}
				*/
				str = (rs.getString(1) + " " + rs.getString(2) + " " +
					  rs.getString(3) + " " + rs.getString(4) + " " +
					  rs.getString(5));				
				addrs.add(str);	
			}
			return addrs;
		} catch (SQLException e) {			
			e.printStackTrace();
		} finally {			
			try {
				pstmt.close();
				con.close();
			} catch (SQLException e) {				
				e.printStackTrace();
			}
		}
		return null;
	}
}
